package org.mark.sell.service.impl;

import org.mark.common.response.Result;
import org.mark.sell.entity.SiteInfo;
import org.mark.sell.mapper.SiteInfoMapper;
import org.mark.sell.service.SiteInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SiteInfoServiceImpl implements SiteInfoService {


    @Resource
    SiteInfoMapper siteInfoMapper;


    @Override
    public Result page(Integer pageNum, Integer pageSize, String name) {
        LambdaQueryWrapper<SiteInfo> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            wrapper.like(SiteInfo::getName, name);
        }

        wrapper.orderByDesc(SiteInfo::getCreateTime);

        Page<SiteInfo> page = siteInfoMapper.selectPage(
                new Page<>(pageNum, pageSize),
                wrapper
        );
        return Result.success(page);
    }
    @Override
    public List<SiteInfo> selectSiteInfoList(SiteInfo siteInfo) {
        return null;
    }

    @Override
    public SiteInfo selectSiteInfoById(Integer id) {
        return siteInfoMapper.selectById(id);
    }

    @Override
    public int insertSiteInfo(SiteInfo siteInfo) {
        return siteInfoMapper.insert(siteInfo);
    }

    @Override
    public int updateSiteInfoById(SiteInfo siteInfo) {
        return siteInfoMapper.updateById(siteInfo);
    }

    @Override
    public int deleteSiteInfoById(Integer id) {
        return siteInfoMapper.deleteById(id);
    }
}
